package com.ss.tmall.service.impl;

import com.ss.tmall.mapper.OrderMapper;
import com.ss.tmall.pojo.Order;
import com.ss.tmall.pojo.OrderExample;
import com.ss.tmall.pojo.User;
import com.ss.tmall.service.OrderService;
import com.ss.tmall.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: ShengShuai
 * @Description:
 * @Date: Created in 下午 21:49  2017/12/28 0028
 * @Modified By:
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    UserService userService;
    @Override
    public  void  add(Order order){
        orderMapper.insert(order);
    }
    @Override
    public  void delete(int id){
        orderMapper.deleteByPrimaryKey(id);

    }
    @Override
    public  void  update(Order order){
        orderMapper.updateByPrimaryKeySelective(order);
    }
    @Override
    public  Order  get(int id){
      return   orderMapper.selectByPrimaryKey(id);
    }
    @Override
    public List<Order> list(){
        OrderExample orderExample=new OrderExample();
        orderExample.setOrderByClause("id desc");
        List<Order> result= orderMapper.selectByExample(orderExample);
        setUser(result);
        return  result;
    }

    public void setUser(List<Order> os) {
        for (Order order:os) {
            setUser(order);
        }
    }
    public  void  setUser(Order order){
        int uid=order.getUid();
        User user =userService.get(uid);
        order.setUser(user);
    }


}

